package com.android.superobstacleavoider;

import javax.microedition.khronos.opengles.GL10;

public class Player {
	private Vector3 m_position;
	private float m_speed;
	private Vector3 m_rotation;
	private float m_rotAngle;
	private Vector3 m_scale;
	private BoundingSphere m_bSphere;
	private ModelData m_playerModel;
	private boolean m_isAlive;

	public static final int MAX_X_VALUE = 20;
	public static final int MAX_ROT_ANGLE = 10;
	
	public boolean m_isMovingLeft = false;
	public boolean m_isMovingRight = false;

	public BoundingSphere getSphere() {
		return m_bSphere;
	}

	public void setModel(ModelData model) {
		m_playerModel = model;
	}

	public ModelData getModel() {
		return m_playerModel;
	}

	public boolean isAlive() {
		return m_isAlive;
	}

	public void setIsAlive(boolean a_isAlive) {
		m_isAlive = a_isAlive;
	}

	public Player() {
		initialize();
	}

	public void initialize() {
		m_isAlive = true;
		m_position = new Vector3(0.0f, -3.0f, -5.0f);
		m_rotation = Vector3.ZERO;
		m_rotAngle = 0.0f;
		m_scale = new Vector3(0.00005f, 0.00005f, 0.00005f);
		m_speed = 40.0f;
		m_bSphere = new BoundingSphere(m_position, 2.5f);
	}

	public void draw(GL10 gl) {
		ModelHandler.drawModel(gl, m_playerModel, m_scale, m_position,
				m_rotation, m_rotAngle, false);
	}

	public void update(float a_dt) {
		if(m_isMovingLeft)
		{
			if(isValidPosX(m_position.X))
				m_position.X -= a_dt * m_speed;
		}
		else if(m_isMovingRight)
		{
			if(isValidPosX(m_position.X))
				m_position.X += a_dt * m_speed;
		}
		m_bSphere.setCenter(m_position);
	}

	public boolean isValidPosX(float x) {
		if (x >= -MAX_X_VALUE && x <= MAX_X_VALUE) {
			return true;
		}
		return false;
	}

	public boolean isValidRotAngle(float angle) {
		if (angle >= -MAX_ROT_ANGLE && angle <= MAX_ROT_ANGLE) {
			return true;
		}
		return false;
	}

	public Vector3 getPos() {
		return m_position;
	}

	// differend setters for position
	public void setPos(Vector3 a_pos) {
		m_position = a_pos;
	}

	public void setPos(float x, float y, float z) {
		m_position = new Vector3(x, y, z);
	}

	public void setPosX(float x) {
		if(isValidPosX(x))
			m_position.X = x;
	}

	public void setPosY(float y) {
		m_position.Y = y;
	}

	public void setPosZ(float z) {
		m_position.Z = z;
	}

	public float getSpeed() {
		return m_speed;
	}

	public void setSpeed(float a_speed) {
		m_speed = a_speed;
	}

	public Vector3 getRot() {
		return m_rotation;
	}

	// Different setters for rotation
	public void setRot(Vector3 a_rot) {
		m_rotation = a_rot;
	}

	public void setRot(float x, float y, float z) {
		m_rotation = new Vector3(x, y, z);
	}

	public void setRotX(float x) {
		m_rotation.X = x;
	}

	public void setRotY(float y) {
		m_rotation.Y = y;
	}

	public void setRotZ(float z) {
		m_rotation.Z = z;
	}

	public float getRotAngle() {
		return m_rotAngle;
	}

	public void setRotAngle(float a_rotAngle) {
		m_rotAngle = a_rotAngle;
	}
}
